package com.young.interfaces.config.model;

/**
 * 配置对象
 *
 * @author wangjy
 * @date 2021/10/19 23:53:10
 */
public class ConfigDTO {
    /**
     * 配置key
     */
    private String key;
    /**
     * 配置值
     */
    private String value;
    /**
     * 配置优先级
     */
    private Integer priority;

    /**
     * 判断是否高优先级
     *
     * @return
     */
    public boolean highPriority() {
        return priority != null && priority == 1;
    }

    /**
     * 静态建造方法
     *
     * @param key      配置key
     * @param value    配置值
     * @param priority 优先级
     * @return
     */
    public static ConfigDTO build(String key, String value, Integer priority) {
        ConfigDTO config = new ConfigDTO();
        config.setKey(key);
        config.setValue(value);
        config.setPriority(priority);
        return config;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("{");
        sb.append("\"key\":").append(key != null ? "\"" : "").append(key).append(key != null ? "\"" : "");
        sb.append(", \"value\":").append(value != null ? "\"" : "").append(value).append(value != null ? "\"" : "");
        sb.append(", \"priority\":").append(priority);
        sb.append('}');
        return sb.toString();
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }
}
